import { BrowserRouter, Route, Routes } from 'react-router-dom';  
import { RouteConfig } from './router/nrouter';
import ErrorBoundary from './component/ErrorBoundary';
import nroutes from './router/nrouter';
// 渲染路由的函数  
function renderRoutes(routes: RouteConfig[], parentPath = '') {  
  return routes.map((route, index) => {  
    const { path, element, children, ...rest } = route;  
    const fullPath = `${parentPath}${path === '/' ? '' : path}`;  
  
    // 如果存在子路由，递归渲染  
    if (children) {  
      return (  
        <Route  
          key={index}  
          path={fullPath}  
          element={element}  
        >  
          {renderRoutes(children, fullPath)}  
        </Route>  
      );  
    }  
  
    // 渲染没有子路由的路由  
    return (  
      <Route  
        key={index}  
        path={fullPath}  
        element={element}  
        {...rest}  
      />  
    );  
  });  
}  
  
// 在您的应用中使用  
 
  
function App() {  
  return (  
    <BrowserRouter>  
      <ErrorBoundary>  
        <Routes>  
          {renderRoutes(nroutes)}  
        </Routes>  
      </ErrorBoundary>  
    </BrowserRouter>  
  );  
}  
export default App;